﻿//------------------------------------------------------------
// shaco Framework
// Copyright © 2017-2021 chang.liu All rights reserved.
// Feedback: 449612236@qq.com
//------------------------------------------------------------

namespace shaco.Base.Net
{
    /// <summary>
    /// 网络套接字，主要负责网络数据传输使用
    /// </summary>
    public interface ISocket
    {
        /// <summary>
        /// 连接网络
        /// <param name="host">主机地址</param>
        /// <param name="port">主机端口号</param>
        /// <param name="connectTimeoutSeconds">连接超时时间</param>
        /// <param name="callback">连接结果回调</param>
        /// </summary>
        void Connect(string host, int port, float connectTimeoutSeconds, System.Action<bool> callback);

        /// <summary>
        /// 断开连接
        /// </summary>
        void Disconnect();

        /// <summary>
        /// 是否已经连接成功
        /// </summary>
        bool IsConnected();

        /// <summary>
        /// 是否有接收数据
        /// </summary>
        bool IsDataAvailable();

        /// <summary>
        /// 发送数据
        /// <param name="data">二进制数据</param>
        /// <return>发送的二进制数据数量，如果返回-1表示发送失败</return>
        /// </summary>
        int Send(byte[] data);

        /// <summary>
        /// 接收数据
        /// <param name="receiveBuffer">接收到的二进制数据</param>
        /// <param name="offset">偏移位置</param>
        /// <return>接收的字节数量</return>
        /// </summary>
        int Receive(byte[] receiveBuffer, int offset);

        /// <summary>
        /// <param name="send">发送超时时间(单位：秒)</param>
        /// <param name="receive">接收超时时间(单位：秒)</param>
        /// </summary>
        void SetTimeoutSeconds(float send, float receive);
    }
}